import { getTopBanners, getHotRecommends } from '@/api/discover/recommend.js'
import { actionType } from './constants'

function changeTopBannersAction(res) {
    return {
        type: actionType.CHANGE_TOP_BANNERS,
        topBanners: res.banners
    }
}

export const getTopBannersAction = () => {
    return dispatch => {
        getTopBanners()
            .then(res => {
                // console.log('then方法',res)
                dispatch(changeTopBannersAction(res))
            })
            .catch(err => {
                // console.log('err方法',err)
                dispatch(err.data)
            })
    }
}

function changeRecommendsAction(res) {
    return {
        type: actionType.CHANGE_HOT_RECOMMENDS,
        hotRecommends: res
    }
}

export const getHotRecommendAction = (limit) => {
    return dispatch => {
        getHotRecommends(limit).then(res => {
            dispatch(changeRecommendsAction(res.result))
        }).catch(err => {
            dispatch(err.data)
        })
    }
}

//以后都这样写  上边的懒得改了
export const changeNewAlbumsAction = (data) => {
    return dispatch => {
        dispatch({
            type: actionType.CHANGE_NEW_ALBUMS,
            newAlbums: data
        })
    }
}